package com.scpii.api.common.exception;

import com.scpii.api.common.base.Response;
import com.scpii.api.common.base.Response.Status;

public class ClientException extends RuntimeException {

	/**
	 * 
	 */
	private static final long serialVersionUID = -3817573290201955838L;

	public ClientException(String msg, Throwable t) {
		super(msg, t);
	}

	public ClientException(String msg) {
		super(msg);
	}

	public ClientException() {

	}

	public Status getStatus() {
		return Response.Status.INVALID_REQUEST;
	}

	@Override
	public String toString() {
		return getSummary();
	}

	public String getSummary() {

		StringBuilder builder = new StringBuilder();

		String delim = "";

		String error = getStatus().getDescription();
		if (error != null) {
			builder.append(delim).append("error=\"").append(error).append("\"");
			delim = ", ";
		}

		String errorMessage = this.getMessage();
		if (errorMessage != null) {
			builder.append(delim).append("errorDescription=\"")
					.append(errorMessage).append("\"");
			delim = ", ";
		}
		return builder.toString();

	}
}
